layui.use(['form', 'upload', 'layer'], function () {
    var form = layui.form;
    form.on('switch(advanceSwitch)', function (data) {
        if (data.elem.checked === true) {
            document.getElementById('advanceOption').style.display = 'table';
        } else {
            document.getElementById('advanceOption').style.display = 'none';
        }
    });

    var upload = layui.upload;
    var uploadInst = upload.render({
        elem: '#fileUpload' //绑定元素
        , url: '/upload' //上传接口
        , accept: 'file'
        , bindAction: '#submit'
        , auto: false
        , before: function () {
            this.data = {
                "password": $('#password').val(),
                "advance": $('#advanceSwitch').prop("checked"),
                "times": $('#times').val(),
                "days": $('#days').val(),
            }
        }
        , done: function (res) {
            if (res.status === 0) {
                return layui.use('layer', function () {
                    var layer = layui.layer
                    layer.open({
                        type: 2,
                        area: ['500px', '500px'],
                        content: ['showcode', 'no'],
                        title: false,
                        closeBtn: 0,
                        shadeClose: true,
                        success: function (layero, index) {
                            var iframe = window['layui-layer-iframe' + index];
                            iframe.getCode(res.code);
                        }
                    })
                });
            }
        }
        , error: function () {
            //请求异常回调
        }
    });


});
